<template>
  <div class="app-container">
    <el-row style="margin-bottom: 5px">
      <el-button
        type="warning"
        plain
        icon="el-icon-download"
        size="mini"
        @click="exportLeaveSchoolSta"
      >导出
      </el-button>
    </el-row>
    <el-table v-loading="loading" :data="LeaveSchoolStaList">
      <el-table-column label="日期" align="center" prop="expectTime"/>
      <el-table-column label="今日离校人数" align="center" prop="todayLeaveNum">
        <template slot-scope="scope">
          <el-link type="primary"><span @click="showLeaveSchoolStusDialog('今日离校学生列表',scope.row,1)">{{scope.row.todayLeaveNum}}</span>
          </el-link>
        </template>
      </el-table-column>
      <el-table-column label="已离校人数" align="center" prop="alreadyLeaveNum">
        <template slot-scope="scope">
          <el-link type="primary"><span @click="showLeaveSchoolStusDialog('已离校学生列表',scope.row,2)">{{scope.row.alreadyLeaveNum}}</span>
          </el-link>
        </template>
      </el-table-column>
      <el-table-column label="未离校人数" align="center" prop="notLeaveNum"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getLeaveSchoolSta"
    />

    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="show"
               :fullscreen="true" @closed="closed">
      <el-form label-position="left" :model="queryParams" ref="queryParams"
               :inline="true">
        <el-form-item  label="" prop="areaCollegeGradeProClass"
                      label-width="170px">
          <el-cascader
            v-model="queryParams.areaCollegeGradeProClass"
            :options="stuClassCasList"
            :props="casProps"
            placeholder="校区/学院/年级/专业班级"
            filterable
            @change="queryStus"></el-cascader>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-refresh" type="primary" size="mini" @click="reset">重置
          </el-button>
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="exportLeaveSchoolStus"
          >导出
          </el-button>
        </el-form-item>
      </el-form>
      <el-table :data="stus" v-loading="stusLoading">
        <el-table-column type="selection" width="50" align="center"/>
        <el-table-column label="姓名" align="center" prop="name" width="70"/>
        <el-table-column label="学院" align="center" prop="collegeName" :show-overflow-tooltip="true"/>
        <el-table-column label="年级" align="center" prop="gradeName" width="60"/>
        <el-table-column label="专业班级" align="center" prop="proClassName"/>
        <el-table-column label="性别" align="center" width="50">
          <template slot-scope="scope">
            <span v-if="scope.row.sex===0">男</span>
            <span v-if="scope.row.sex===1">女</span>
          </template>
        </el-table-column>
        <el-table-column label="类别" align="center" width="65">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.stu_type" :value="scope.row.type"/>
          </template>
        </el-table-column>
        <el-table-column label="学号" align="center" prop="stuNo" width="130"/>
        <el-table-column label="身份证号" align="center" prop="idNum"/>
        <el-table-column label="校区" align="center" width="65">
          <template slot-scope="scope">
            <span v-if="scope.row.schoolArea===1">新校区</span>
            <span v-if="scope.row.schoolArea===2">老校区</span>
          </template>
        </el-table-column>
        <el-table-column label="住宿信息" align="center" width="90">
          <template slot-scope="scope">
            <span>{{scope.row.buildingName}}-{{scope.row.roomName}}-{{scope.row.bedName}}</span>
          </template>
        </el-table-column>
        <el-table-column label="手机号" align="center" prop="phone" width="108"/>
        <el-table-column label="状态" align="center" prop="status">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.stu_status" :value="scope.row.status"/>
          </template>
        </el-table-column>
        <el-table-column label="现居地址" align="center" prop="addrNow" :show-overflow-tooltip="true"/>
      </el-table>
      <pagination
        v-show="stusTotal>0"
        :total="stusTotal"
        :page.sync="stusQuery.pageNum"
        :limit.sync="stusQuery.pageSize"
        @pagination="getLeaveSchoolStus"
      />
    </el-dialog>


  </div>
</template>

<script>
  import {listStu, leaveSchoolSta, leaveSchoolStus} from "@/api/stu/stu";
  import {findChildrenStuClassCasById, findChildrenStuClassCasByIds} from "@/api/stu/class";


  export default {
    name: "index",
    created() {
      this.getLeaveSchoolSta()
      this.getStuClassCas()
    },
    dicts: ['stu_status', 'stu_type'],
    data() {
      return {
        loading: false,
        stusLoading: false,
        total: 0,
        stusTotal: 0,
        LeaveSchoolStaList: [],
        stus: [],
        queryParams: {
          pageSize: 10
        },
        stusQuery: {
          pageSize: 10
        },
        title: '',
        show: false,
        stuClassCasList:[],
        casProps: {
          label: 'label',
          value: 'id',
          checkStrictly: true
        },
      }
    },
    methods: {
      getLeaveSchoolSta() {
        this.loading = true
        leaveSchoolSta().then(res => {
          this.LeaveSchoolStaList = res.rows
          this.total = res.total;
          this.loading = false
        })
      },
      getLeaveSchoolStus() {
        this.stusLoading = true
        leaveSchoolStus(this.queryParams).then(res => {
          this.stus = res.rows
          this.stusTotal = res.total;
          this.stusLoading = false
        })
      },
      showLeaveSchoolStusDialog(title, row, type) {
        this.title = title
        this.queryParams.expectTime=row.expectTime
        this.queryParams.type=type
        this.show = true
        this.getLeaveSchoolStus()
      },
      closed() {
        this.show = false
        this.stus = []
      },
      getStuClassCas() {
        findChildrenStuClassCasById({parentId: 0}).then(res => {
          this.stuClassCasList = res.data
        })
      },
      queryStus(data){
        this.queryParams.areaCollegeGradeProClass=data
        this.getLeaveSchoolStus()
      },
      reset(){
        this.queryParams.areaCollegeGradeProClass=[]
        this.getLeaveSchoolStus()
      },
      exportLeaveSchoolStus(){
        this.download('stuManage/stu/exportLeaveSchoolStus', {
          ...this.queryParams
        }, `离校学生列表${new Date().getTime()}.xlsx`)
      },
      exportLeaveSchoolSta(){
        this.download('stuManage/stu/exportLeaveSchoolSta', {
          ...this.queryParams
        }, `学生离校统计数据_${new Date().getTime()}.xlsx`)
      }
    }
  }
</script>

<style scoped>

</style>
